﻿<cfmodule template="../../tag/layout.cfm">
<cfinclude template="../../inc/lib.cfm">
<!--- 表格显示 --->
<table id="grid"></table>
<!--- 搜索及操作工具条 --->
<div id="toolbar" style="display: none;">
	<form id="searchForm">
		<table>
			<tr>
				
				<td>姓名</td>
				<td><input name="name" style="width: 80px;" /></td>
				<td>角色描述</td>
				<td><input name="description" style="width: 120px;" /></td>
				<td>创建时间</td>
				<td>
					<input name="created_ge"  class="easyui-datebox" style="width:100px"/>
					-
					<input name="created_le"  class="easyui-datebox" style="width:100px"/>
				</td>
				<td>
					<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom',plain:true" onclick="grid.datagrid('load',fw.serializeObject($('#searchForm')));">过滤</a>
					<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom_out',plain:true" onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a>
				</td>
			</tr>
		</table>
	</form>
	<table>
		<cfif havePermission(QueryStringChangeVar("action",getCurrentPageType() & ".save"))>
		<tr>
			<td>
				<table>
					<tr>
						<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-note_add',plain:true" onclick="addFun();">添加</a></td>
					</tr>
				</table>
			</td>
		</tr>
		</cfif>
	</table>
</div>
</cfmodule>

<script type="application/javascript">
//删除操作
var removeFun = function(id) {
    parent.$.messager.confirm('询问', '您确定要删除此记录？',
    function(r) {
        if (r) {
            $.post('?action=role.delete', {
                id: id
            },
            function() {
                grid.datagrid('reload');
            },
            'json');
        }
    });
};
//查看操作
var showFun = function(id) {
    var dialog = parent.fw.modalDialog({
        title: '查看信息',
        url: '?action=role.form&id=' + id,
        buttons: [{
            text: '关闭窗口',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        }]
    });
};
//新增操作
var addFun = function() {
    var dialog = parent.fw.modalDialog({
        title: '新增信息',
        url: '?action=role.form',
        buttons: [
        {
            text: '新增记录',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
            }
        },{
            text: '关闭窗口',
            handler: function() {
               dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        }]
    });
}
//修改操作
var editFun = function(id) {
    var dialog = parent.fw.modalDialog({
        title: '修改信息',
        url: '?action=role.form&id=' + id,
        buttons: [
        {
            text: '修改记录',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
            }
        },{
            text: '关闭窗口',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        }]
    });
};

//角色授权
var grantFun = function(id) {
	var dialog = parent.fw.modalDialog({
		title : '角色授权',
		url : '?action=role.grant&id=' + id,
		buttons : [ {
			text : '授权',
			handler : function() {
				dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
			}
		},{
            text: '关闭窗口',
            handler: function() {
                dialog.find('iframe').get(0).contentWindow.closeDialog(dialog);
            }
        } ]
	});
};

$(function(){
	//列表操作
	var gird;
	grid = $('#grid').datagrid({
		fit: true,
		border:false,
		collapsible:false,
		pagination:true,
		singleSelect:true,
		rownumbers:true,
		sortName:'seq',
		sortOrder:'desc',
		toolbar : '#toolbar',
		url:'?action=role.list',
		columns:[[
			{field:'id',title:'ID',width:40,sortable:true},
			{field:'name',title:'用户名称',width:180,sortable:true},
			{field:'description',title:'角色描述',width:180},
			{field:'created',title:'添加时间',width:80,align:'center',sortable:true},
			{field:'edited',title:'修改时间',width:80,align:'center',sortable:true}, 
			{field:'seq',title:'排序',width:80,align:'center',sortable:true}, 
			{
				title : '操作',
				field : 'action',
				width : '90',
				formatter : function(value, row) {
					var str = '';
						<cfif havePermission(QueryStringChangeVar("action",getCurrentPageType() & ".form"))>
						str += fw.formatString('<img class="iconImg ext-icon-note" title="查看" onclick="showFun(\'{0}\');"/>', row.id);
						</cfif>
						
						<cfif havePermission(QueryStringChangeVar("action",getCurrentPageType() & ".update"))>
						str += fw.formatString('<img class="iconImg ext-icon-note_edit" title="编辑" onclick="editFun(\'{0}\');"/>', row.id);
						</cfif>
						
						<cfif havePermission(QueryStringChangeVar("action",getCurrentPageType() & ".grant"))>
						str += fw.formatString('<img class="iconImg ext-icon-key" title="授权" onclick="grantFun(\'{0}\');"/>', row.id);
						</cfif>
						
						<cfif havePermission(QueryStringChangeVar("action",getCurrentPageType() & ".delete"))>
						str += fw.formatString('<img class="iconImg ext-icon-note_delete" title="删除" onclick="removeFun(\'{0}\');"/>', row.id);
						</cfif>
						
					return str;
				}
			} 
		]],
		onLoadSuccess : function(data) {
			$('.iconImg').attr('src', fw.pixel_0);
		}
	});
});
</script>